/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uit_vendor_management;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author QuangKhoi
 */
public class DataTable extends DefaultTableModel {
    public DataTable() {
        
    }
    
    public Date getDate(int i, int j) {
        String dateFormat = "dd/MM/yyyy";
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        String strDate = super.getValueAt(i, j).toString();
        Date date = null;
        try {
            date = sdf.parse(strDate);
        } catch (ParseException ex) {
            Logger.getLogger(DataTable.class.getName()).log(Level.SEVERE, null, ex);
        }
        return date;
    }
    
    public Integer getInteger(int i, int j) {
        if (this.getValueAt(i, j) == null) return new Integer(0);
        return Integer.parseInt(super.getValueAt(i, j).toString());
    }
    
    public Float getFloat(int i, int j) {
        if (this.getValueAt(i, j) == null) return new Float(0.0);
        return Float.parseFloat(super.getValueAt(i, j).toString());
    }
    
    public String getString(int i, int j) {
        if (this.getValueAt(i, j) == null) return "";
        return this.getValueAt(i, j).toString();
    }
}
